package com.demo.hello;

import java.util.Calendar;
import java.util.Date;

public class GreetAboutTimeImpl implements GreetAboutTime {
    private final Date now;

    public GreetAboutTimeImpl(Date now) {
        this.now = now;
    }
    private int getHour() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(now);
        return calendar.get(Calendar.HOUR_OF_DAY);
    }
    @Override
    public String greet() {
        int hour = getHour();
        String words;
        if(hour>=6 && hour<12) {
            words = "Good morning!";
        } else if(hour>=12 && hour<19) {
            words = "Good afternoon!";
        } else {
            words = "Good night!";
        }
        return words;
    }
}
